package com.zijie.shop.order.api.api;

import com.zijie.core.util.JsonResult;
import com.zijie.order.model.OrderItem;
import com.zijie.order.service.OrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/orderItem")
public class OrderItemApi {
    private OrderItemService orderItemService;
    @Autowired
    public void setOrderItemService(OrderItemService orderItemService) {
        this.orderItemService = orderItemService;
    }
    @GetMapping("/findByOrderId/{id}")
    public ResponseEntity<JsonResult<?>> findByOrderId(@PathVariable Integer id){
//        System.out.println(id);
        return ResponseEntity.ok(JsonResult.success(orderItemService.findOrderItemDetailsByOrderId(id)));
    }
    //新增多个订单项
    @PostMapping("/save")
    public ResponseEntity<JsonResult<?>> save(@RequestBody List<OrderItem> orderItems) {
        boolean save = orderItemService.saveOrderItem(orderItems);
        return ResponseEntity.ok(JsonResult.success(save));
    }

}